<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>叩丁狼骡窝窝后台管理系统</title>
<#include "../common/header.ftl" >
    <link type="text/css" rel="stylesheet" href="/js/plugins/uploadifive/uploadifive.css"/>
    <script type="text/javascript" src="/js/plugins/uploadifive/jquery.uploadifive.min.js"></script>

    <script>
        $(function () {
            // 修改
            $(".inputBtn").click(function () {
                $('#inputModal input').val('');
                $('#inputModal select').val('');
                var json = $(this).data('json');
                if (json) {
                    $('#inputModal input[name=id]').val(json.id);
                    $('#inputModal input[name=title]').val(json.title);
                    $('#inputModal input[name=subTitle]').val(json.subTitle);
                    $('#inputModal select[name=state]').val(json.state);
                    $('#inputModal input[name=sequence]').val(json.sequence);
                    $('#inputModal select[name=travelId]').val(json.travelId);
                    $("#coverUrl").attr('src', json.coverUrl);
                }
                $('#inputModal').modal("show");
            });


            $('.btn-submit').click(function () {
                $('#editForm').ajaxSubmit(function (data) {
                    handleMessage(data);
                })
            });


            //图片上传
            $('.imgBtn').uploadifive({
                'auto': true,    //自动提交
                'uploadScript': '/uploadImg',  //图片上传过来处理路径(接受)
                buttonClass: "btn-link",  //按钮的样式
                'fileObjName': 'pic',  // 图片文件上传之后, 在springmvc 映射方法接受的参数名
                'buttonText': '浏览...',  //按钮上面文字
                'fileType': 'image',   //指定上传的图片
                'multi': false,   //是否为多文件上传, 此处设置单文件
                'fileSizeLimit': 5242880,  //文件上传大小
                'removeCompleted': true, //取消上传完成提示
                'uploadLimit': 1,  //一次允许上传文件个数
                //'queueSizeLimit'  : 10,  //文件上传等待队列大小
                'overrideEvents': ['onDialogClose', 'onError'],    //onDialogClose 取消自带的错误提示
                'onUploadComplete': function (file, data) {

                    //data 请求方法处理完之后, 传回来的数据: 约定: 图片的路径(url)
                    $("#imgUrl").attr("src", "/" + data);
                    $("#coverUrl").val("/" + data);

                },
                onFallback: function () {
                    $.messager.alert("温馨提示", "该浏览器无法使用!");
                }
            });

        })
    </script>

</head>
<body>

<#assign currentMenu="travelCommend"/>
<div class="container-fluid " style="margin-top: 20px">
<#include "../common/top.ftl">
    <div class="row">
        <div class="col-sm-2">
        <#include "../common/menu.ftl">
        </div>
        <div class="col-sm-10">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">游记推荐管理</h1>
                </div>
            </div>
            <!--高级查询--->
            <form class="form-inline" id="searchForm" action="/travelCommend/list" method="post">
                <input type="hidden" name="currentPage" id="currentPage" value="1">
                <a href="#" class="btn btn-success inputBtn"><span class="glyphicon glyphicon-plus"></span>
                    添加</a>
            </form>

            <table class="table table-striped table-hover">
                <thead>
                <tr>
                    <th>编号</th>
                    <th>封面</th>
                    <th>标题</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>

                </thead>
            <#list pageInfo.list as entity>
                <tr>
                    <td>${entity_index + 1}</td>
                    <td><img src="${entity.coverUrl}" width="30px"/></td>
                    <td>${entity.title}</td>
                    <td>${entity.stateDisplay!}</td>
                    <td>
                        <a class="btn btn-info btn-xs inputBtn" href="javascript:void(0);"
                           data-json='${(entity.jsonString)!}'>
                            <span class="glyphicon glyphicon-edit"></span> 编辑
                        </a>

                        <a href="javascript:;" class="btn btn-danger btn-xs deleteBtn"
                           data-url="/travelCommend/delete?id=${entity.id}">
                            <span class="glyphicon glyphicon-trash"></span> 删除
                        </a>
                    </td>
                </tr>
            </#list>
            </table>
        <#include "../common/page.ftl" />
        </div>
    </div>
</div>


<#--编辑模态框-->
<div class="modal fade" id="inputModal" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title">游记推荐添加/编辑</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/travelCommend/saveOrUpdate" method="post" id="editForm"
                      enctype="multipart/form-data">
                    <input type="hidden" name="id">

                    <div class="form-group">
                        <label for="name" class="col-sm-4 control-label">标题：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="title" name="title">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="name" class="col-sm-4 control-label">副标题：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="subTitle" name="subTitle">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">封面：</label>
                        <div class="col-sm-6">
                            <input type="hidden" class="form-control" id="coverUrl" name="coverUrl" value="">
                            <img src="/images/default.jpg" width="100px" id="imgUrl">
                            <button type="button" class="imgBtn">浏览</button>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">游记：</label>
                        <div class="col-sm-6">
                            <select class="form-control" id="travelId" name="travelId">
                                <option value="-1">--请选择--</option>
                            <#list travels as t>
                                <option value="${t.id}">${t.title}</option>
                            </#list>
                            </select>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-4 control-label">状态：</label>
                        <div class="col-sm-6">
                            <select class="form-control" id="state" name="state">
                                <option value="0">普通</option>
                                <option value="1">禁用</option>
                            </select>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-4 control-label">排序：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="sequence" name="sequence" placeholder="请输入序号">
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary btn-submit">保存</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

</body>
</html>